package com.learn.springcloud.second.web;

import com.alibaba.fastjson.JSON;
import com.learn.springcloud.second.web.model.HandleResult;
import com.learn.springcloud.second.web.model.UserInfoModel;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author lwt<br>
 * @description <br>
 * @date 2020/8/17
 */
@Slf4j
@RestController
@RequestMapping(value = "/serviceSecond")
public class LearnTestController {

    @Autowired
    private Environment environment;

    @RequestMapping(value = "/testGet")
    public HandleResult<UserInfoModel> testGet(Long pkId, String userName) {
        UserInfoModel userInfoModel = new UserInfoModel();
        userInfoModel.setPkId(pkId);
        if (StringUtils.isBlank(userName)) {
            userName = "内部设置";
        }
        userInfoModel.setName(userName);
        userInfoModel.setRemarks("这是备注信息。。。。。。！");
        userInfoModel.setCreateTime(new Date());
        log.info("serviceSecond-testGet pkId={},userName={},userInfo={}", pkId, userName, JSON.toJSONString(userInfoModel));
        return HandleResult.success(userInfoModel);
    }

    @RequestMapping(value = "/testPost", method = RequestMethod.POST)
    public HandleResult<UserInfoModel> testPost(@RequestBody UserInfoModel userInfoModel) {
        log.info("serviceSecond-testPost userInfo={}", JSON.toJSONString(userInfoModel));
        userInfoModel.setRemarks("接受到并修改了备注信息");
        return HandleResult.success(userInfoModel);
    }
}
